package Util;

import java.util.Calendar;

import javax.swing.JOptionPane;

import Vo.TimeLimitItem;

import jxl.Cell;
import jxl.Sheet;

public class CommonUtil {
   public boolean isEmpty(String str){
	   return (str == null || str.equals(""));
   }
   
   public static  void reminderAndExit(String message){
	   JOptionPane.showMessageDialog(null, message);
	   System.exit(0);
   }
   
   public static boolean isDateVaild(int startMonth, int startDate, int startHour,
			int startMin, int endMonth, int endDate, int endHour, int endMin) {
		if (endMonth < startMonth) {
			return false;
		}

		if (endMonth > startMonth) {
			return true;
		}

		if (endDate < startDate) {
			return false;
		}

		if (endDate > startDate) {
			return true;
		}

		if (endHour < startHour) {
			return false;
		}

		if (endHour > startHour) {
			return true;
		}

		if (endMin < startMin) {
			return false;
		}
		return true;
	}
   
   public static boolean isTimeForSomething(TimeLimitItem TimeLimitItem) {
		// TODO Auto-generated method stub
		TimeLimitItem timeLimitItem = TimeLimitItem;
			
		Calendar ca = Calendar.getInstance();
		int month = ca.get(Calendar.MONTH);
		month++;
		int date = ca.get(Calendar.DATE);
		int hour = ca.get(Calendar.HOUR_OF_DAY);
		int min = ca.get(Calendar.MINUTE);

		if (!CommonUtil.isDateVaild(timeLimitItem.getStartMonth(),
				timeLimitItem.getStartDate(), timeLimitItem.getStartHour(),
				timeLimitItem.getStartMin(), month, date, hour, min)) {
			return false;
		}

		if (!CommonUtil.isDateVaild(month, date, hour, min,
				timeLimitItem.getEndMonth(), timeLimitItem.getEndDate(),
				timeLimitItem.getEndHour(), timeLimitItem.getEndMin())) {
			return false;
		}
		return true;
	}
   
   public static Cell[][] returnCellArray(Sheet sheet,int colomn){
	   Cell[][] cellArray = new Cell[sheet.getRows()][colomn];
	   for (int i = 0; i < sheet.getRows(); i++) {
		   for(int j = 0 ; j < colomn ; j++){
			   cellArray[i][j]  = sheet.getCell(j,i);
		   }
		}
	   return cellArray;
   }
}
